package com.zuxia.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zuxia.entity.Apply;
import com.zuxia.entity.Staff;
import com.zuxia.service.IApplyService;
import com.zuxia.service.IStaffService;
import com.zuxia.uilt.PageModel;

@Controller()
@Scope("prototype")
@ParentPackage("struts-default")
@Namespace("/")
@Results({
		@Result(name = "selectApy", type = "dispatcher", location = "/admin/chaApply.jsp"),
		@Result(name = "Y", type = "redirectAction", location = "/findApply"),
		@Result(name = "empty", type = "dispatcher", location = "/admin/empty.jsp"),
		@Result(name = "addOK", type = "dispatcher", location = "/index.jsp")
		
})
		 
		

public class ApplyAction extends ActionSupport implements ModelDriven<Apply> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Apply apply = new Apply();
	private Staff staff = new Staff();
	@Override
	public Apply getModel() {
		// TODO Auto-generated method stub
		return apply;
	}
	@Autowired
	private IStaffService staffService;
	@Autowired
	private IApplyService apyservice;
	private int pageNo = 1;// ��̬�ı� ҳ��ȡ��
	private String zname = "";
	private PageModel<?> pm;
	
	public Staff getStaff() {
		return staff;
	}
	public void setStaff(Staff staff) {
		this.staff = staff;
	}
	public IStaffService getStaffService() {
		return staffService;
	}
	public void setStaffService(IStaffService staffService) {
		this.staffService = staffService;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public PageModel<?> getPm() {
		return pm;
	}

	public void setPm(PageModel<?> pm) {
		this.pm = pm;
	}

	public Apply getApply() {
		return apply;
	}

	public void setApply(Apply apply) {
		this.apply = apply;
	}

	public IApplyService getApyservice() {
		return apyservice;
	}

	public void setApyservice(IApplyService apyservice) {
		this.apyservice = apyservice;
	}

	public String getZname() {
		return zname;
	}

	public void setZname(String zname) {
		this.zname = zname;
	}

	@SuppressWarnings("unchecked")
	@Action("findApply")
	public String findApply() {
		pm = new PageModel();
		List list = apyservice.selectApply(pageNo, zname);
		if (list.size() > 0) {
			pm.setList(list);
			pm.setCount(apyservice.apysize());
			pm.setPageNo(pageNo);
			pm.setPageSize(5);
			ActionContext.getContext().put("apy", pm);
			int sumPage = pm.getSumPage();
			ActionContext.getContext().put("sumPage", sumPage);
			return "selectApy";
		}
		return "empty";
	}
	//ɾ��
	@Action("deleteApply")
	public String deleteApply() {
		apyservice.delapy(apply);
		return "Y";
	}
	//录用	经过编号查询出信息，再将查询出的数据添加到与员工表，最后在删除应聘表里的该条数据
	@Action("lyApply")
	public String lyApply() {
		apply = apyservice.updapy(apply);//查询出信息
		//一个员工对象出来，把应聘表里查询出来的数据放到里面
		staff.setStaffCarid(apply.getApplyCard());
		staff.setPosit(apply.getPosit());
		staff.setStaffName(apply.getApplyName());
		staff.setStaffPhone(apply.getApplyPhone());
		staff.setStaffSex(apply.getApplySex());
		staffService.svaeStaff(staff);
		apply.toString();
		apyservice.delapy(apply);
		return "Y";
	}
	
	//招聘
	@Action("addApply")
	public String addApply() {
		apyservice.addapy(apply);
		return "addOK";
	}
}
